<template>
  <div class="home">
    <!-- 顶部导航 -->
    <van-nav-bar title="首页" fixed />
    <!-- 轮播图 -->
    <van-swipe class="my-swipe" :autoplay="2000" indicator-color="#90f">
      <van-swipe-item v-for="(item, index) in banners" :key="index">
        <img :src="item.pic" alt="" width="100%" />
      </van-swipe-item>
    </van-swipe>
    <!-- 区域标题 -->
    <div class="section-title">
      <span class="line"> </span>
      编辑推荐
    </div>
    <!-- 歌单 -->
    <div class="music-list">
      <div class="items" v-for="item in perList" :key="item.id">
        <div class="content">
          <img :src="item.picUrl" alt="" />

          <p>{{ item.name }}</p>
        </div>
      </div>
    </div>

    <!-- 区域标题 -->
    <div class="section-title">
      <span class="line"> </span>
      最新音乐
    </div>
    <!-- 列表 -->
    <div class="song-list">
      <van-cell
        v-for="item in newList"
        :key="item.id"
        :title="item.name"
        size="large"
        :label="item.song.artists[0].name"
        @click="$router.push({ path: '/play', query: { id: item.id } })"
      >
        <!-- 使用 right-icon 插槽来自定义右侧图标 -->
        <template #right-icon>
          <van-icon
            name="play-circle-o"
            size="35"
            color="#09f"
            class="search-icon"
          />
        </template>
      </van-cell>
    </div>
  </div>
</template>

<script>
export default {
  name: "Home",
  data() {
    return {
      banners: [],
      perList: [],
      newList: []
    };
  },
  methods: {},
  created() {
    this.$axios({
      url: "/banner?type=2",
      method: "get"
    }).then(res => {
      //成功回调
      // console.log(res);
      this.banners = res.data.banners;
    });
    this.$axios({
      url: "/personalized",
      method: "get",
      params: { limit: 14 }
    }).then(res => {
      //成功回调
      // console.log(res);
      this.perList = res.data.result;
    });
    this.$axios({
      url: "/personalized/newsong",
      method: "get",
      params: { limit: 8 }
    }).then(res => {
      //成功回调
      // console.log(res);
      this.newList = res.data.result;
    });
  }
};
</script>
<style lang="less">
.home {
  padding-top: 46px;
  .van-nav-bar {
    background: linear-gradient(45deg, #09f, #0f9, #9f0, #90f, #f09, #f90);
  }
}

.section-title {
  height: 50px;
  position: relative;
  background: #fcfcfd;
  border-bottom: 1px solid #e6e6e6;
  line-height: 50px;
  color: gray;
  padding-left: 10px;
  .line {
    width: 4px;
    background-color: #d43c33;
    height: 20px;
    left: 0;
    top: 15px;
    position: absolute;
  }
}
.swipe-img {
  width: 100%;
}
.music-list {
  display: flex;
  flex-wrap: wrap;
  .items {
    box-sizing: border-box;
    width: 33.333%;
    padding: 0 2px;
    margin-bottom: 10px;
    img {
      display: block;
      width: 100%;
    }
    p {
      padding: 0;
      margin: 0;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
      padding: 2px;
      font-size: 14px;
      color: gray;
    }
  }
}
.song-list .play-icon {
  font-size: 30px;
  color: gray;
}
.song-list {
  .van-cell__title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
</style>
